<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div class="searchArea">
				<form id="searchBar">
					<div class="fieldset1 clearFix">
						<div class="FXBR">
							<div class="fieldBox">
								<div class="label">开户银行</div>
								<div class="field">
									<input type="text" name="bank" class="ui-textbox">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">银行账号</div>
								<div class="field">
									<input type="text" id="bankAccount" name="bankAccount" class="ui-textbox">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">所属集团公司</div>
								<div class="field">
									<select id="groupCompanyId" name="groupCompanyId" >
										<option value="">请选择</option>
										<c:forEach items="${fncGroupCompanyList}" var="fncGroupCompany">
											<option value="${fncGroupCompany.id}">${fncGroupCompany.name}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">账户性质</div>
								<div class="field">
									<select id="bankNature" name="bankNature" >
										<option value="">请选择</option>
										<c:forEach items="${bankNatureList}" var="item">
											<option value="${item.key}">${item.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">账户状态</div>
								<div class="field">
									<select id="accountStatus" name="accountStatus" >
										<option value="">请选择</option>
										<c:forEach items="${accountStatusList}" var="item">
											<option value="${item.key}">${item.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">是否在线账户</div>
								<div class="field">
									<select id="isOnlineAccount" name="isOnlineAccount">
										<option value="">请选择</option>
										<option value="1">是</option>
										<option value="0">否</option>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">是否有网银</div>
								<div class="field">
									<select id="isNetBank" name="isNetBank" >
								<option value="">请选择</option>
								<option value="1">是</option>
								<option value="0">否</option>
							</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">是否停用</div>
								<div class="field">
									<select id="isStopUse" name="isStopUse" >
										<option value="">请选择</option>
										<option value="1">已停用</option>
										<option value="0">未停用</option>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">账户归属部门</div>
								<div class="field">
									<select id="buOrgcd" name="buOrgcd" >
										<option value=""></option>
										<c:forEach items="${buOrgCdList}" var="item">
											<option value="${item.key}">${item.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
						</div>
						<div class="clearFix"></div>

						<div class="btnsBox formBtns notRight">
							<span id="searchBtn" class="sq-button-round">查询</span> 
							<span id="clearBtn" class="sq-button-round">清空</span> 
							<sys:funcAuth resCd="fncGroupCompanyAccount_add">
								<span class="sq-button-round" onclick="toSave('','add');">新增账户</span> 
							</sys:funcAuth>
						
							<span class="sq-button-round" onclick="startFlow('openAccount');">开户申请</span>
							<span class="sq-button-round" onclick="startFlow('closeAccount');">销户申请</span>
							<span class="sq-button-round" onclick="toFlowList();">流程历史</span>
							
							<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide" />
						</div>

					</div>
				</form>
			</div>
			<!-- 列表显示块 -->
			<div id="ligergrid1" class="sq-grid"></div>

		</div>
	</div>



	<script type="text/javascript">
	var grid = null;
	var updateId = null;
	$(function () {
		$("#searchBar").ligerForm();
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	 
	//新增修改集团公司保存 
	 $("#save").click(function(event) {
	        var form = liger.get("addForm");
	         if (!form.valid()) {
	        	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
	            return false; 
	        } 
	        var data = form.getData();
	         if(data) {
		        data["id"] =updateId;
	        }
	         console.log(data);
	         /*return;  */
	        $.ligerDialog.hide();
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: '<%=path%>/account/fncGroupCompanyAccountAccount/save.do',
				beforeSend:function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
	    });
	
	
	 function del(id){
		 
		 $.ligerDialog.confirm("确认要删除该集团公司吗?", function (flag) {
			 if(!flag) return;
			 var wait_dialog = null;
			 $.ajax({
				type: 'get',
				dataType:'json',
				url: '<%=path%>/account/fncGroupCompanyAccount/removeById.do?id='+id,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
				},success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				},error:function (XMLHttpRequest, textStatus, errorThrown) { 
					wait_dialog.close();
					$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
				}
			});
		 });
	 }
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/account/fncGroupCompanyAccount/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '状态',
	            	render: function (rowdata, rowindex, value) { 
	            		var h='';
	                	if(rowdata.rday > 10){//当系统时间-流程发起时间>10天，则“亮红灯”提醒
	                		h += '<span title="当系统时间-流程发起时间>10天"><img width="20px" height="20px" src="<%=path%>/resource/lib/images/redpoticon.png"><span>';
	                	}
		                return h;
	           		}
				},
				{ display: '账户状态', name: 'accountStatusNm'},
				{ display: '所属集团公司', name: 'fncGroupCompanyDTO.name' },
				{ display: '开户银行', name: 'bankNm'},
				{ display: '开户银行名称', name: 'bankName' },
				{ display: '银行账号', name: 'bankAccount'},
				/* { display: '开户地',
					render:function (rowdata, rowindex, value){
						return rowdata.bankProv + rowdata.bankCity;
					}
				},
				{ display: '账户性质', name: 'bankNatureNm'}, */
				{ display: '账户用途', name: 'bankUse'},
				{ display: '账户归属部门', name: 'buOrgcdNm'},
				{ display: '流程发起人',
					render:function (rowdata, rowindex, value){
						var h="";
						if(rowdata.accountStatus==2 || rowdata.accountStatus==5) {
							if(rowdata.applCancelUsrNm) {
								h = rowdata.applCancelUsrNm;
							}else if(rowdata.applUsrNm) {
								h = rowdata.applUsrNm;
							}
						}
						
						return h;
					}
				},
				{ display: '是否停用',
					render:function (rowdata, rowindex, value){
						var h="";
						if(rowdata.isStopUse == 1) {
							h = '已停用';
						}else if(rowdata.isStopUse == 0) {
							h = '未停用';
						}
						return h;
					}
				},
				{
					display:'操作',
					width:220,
					render:function (rowdata, rowindex, value){
						var h="";
						
						if(rowdata.accountStatus==1 || rowdata.accountStatus==3) {
							
							<sys:funcAuth resCd="fncGroupCompanyAccount_updateAll">
							h+='<a class="sq-button-hasicon" href="javascript:toSave(';
			            	h+="'"+rowdata.id+"','updateAll'";
			                h+=")\"><i class='sqBtnIco_4'></i>修改全部</a>";
			                </sys:funcAuth>
			                <sys:funcAuth resCd="fncGroupCompanyAccount_update">
			                h+='<a class="sq-button-hasicon" href="javascript:toSave(';
			            	h+="'"+rowdata.id+"','updatePart'";
			                h+=")\"><i class='sqBtnIco_4'></i>修改</a>";
			                </sys:funcAuth>
						}
		                
		                h+='<a class="sq-button-hasicon" href="javascript:toSave(';
		            	h+="'"+rowdata.id+"','view'";
		                h+=")\"><i class='sqBtnIco_4'></i>详情</a>";
						
		                <sys:funcAuth resCd="fncGroupCompanyAccount_isStopUse">
							if(rowdata.isStopUse==1) {
								h+='<a class="sq-button-hasicon" href="javascript:updateIsStopUse(';
				            	h+="'"+rowdata.id+"','0','启用'";
				                h+=")\"><i class='sqBtnIco_4'></i>启用</a>";
							}else if(rowdata.isStopUse==0) {
								h+='<a class="sq-button-hasicon" href="javascript:updateIsStopUse(';
				            	h+="'"+rowdata.id+"','1','停用'";
				                h+=")\"><i class='sqBtnIco_4'></i>停用</a>";
							}
						</sys:funcAuth>
		                
						return h;
					}
				},
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			isScroll: true,
			checkbox:true,//列表是否有选择框
			rownumbers:true,//列表是否有行号
			
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
	}
	
	function startFlow(operate){
	
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length == 0){
			$.ligerDialog.SQalert({content: "请选择记录" , SQ_type: "warning" });
			return;
		}
		if(selectedRows.length >= 2){
			$.ligerDialog.SQalert({content: "只能选择一条记录" , SQ_type: "warning" });
			return;
		}
		
		var title;
		if(operate == "openAccount") {
			if(selectedRows[0].accountStatus != 1){
				$.ligerDialog.SQalert({content: "只有‘未审核’状态，才能发起开户流程" , SQ_type: "warning" });
				return;
			}
			title = "开户申请";
		}else if(operate == "closeAccount") {
			title = "销户申请";
			if(selectedRows[0].accountStatus != 3){
				$.ligerDialog.SQalert({content: "只有‘正常’状态，才能发起销户流程" , SQ_type: "warning" });
				return;
			}
		}
		
		var timestamp = new Date().getTime();
		var param = '<%=path%>/account/fncGroupCompanyAccount/toStartFlow.do?id=' + selectedRows[0].id+'&operate='+operate;
		Add_navTab('fncGroupCompanyAccountFlow'+timestamp,title,param, function () {
			grid.reload();
		});
		
	}
	
	function toSave(id,operate){
		var title = "账户详情";
		if(operate == "updateAll" || operate == "updatePart") {
			title = "账户修改";
		}else if(operate == "add") {
			title = "账户新增";
		}
		var timestamp = new Date().getTime();
		var param = '<%=path%>/account/fncGroupCompanyAccount/toSave.do?id=' + id+'&operate='+operate;
		Add_navTab('fncGroupCompanyAccount'+timestamp,title,param, function () {
			grid.reload();
		});
	}
	
	function updateIsStopUse(id,isStopUse,tip){
		$.ligerDialog.confirm('确定'+tip+'吗?', function (flag) {
			if(flag == false)return;
				var wait_dialog = null;
				$.ajax({
					type: 'get',
					dataType: 'json',
					url: '<%=path%>/account/fncGroupCompanyAccount/updateIsStopUse.do?id='+id+"&isStopUse="+isStopUse,
					beforeSend : function() {
						wait_dialog = $.ligerDialog.SQalert({
							content : LogUtils.LOG_CMM_DATA_LOADING,
							SQ_type : "waitting"
						});
					},
					success : function(msg) {
						console.log(msg.success);
						wait_dialog.close();
						if (msg.success == 1) {
							grid.reload();
						} else {
							$.ligerDialog.SQalert({
								content : msg.info,
								SQ_type : "error"
							});
						}
					}
				});
		});
	}
	

		//清空按钮事件
		function clearBtnEvent() {
			$("#clearBtn").click(function(event) {
				$("#resetBtn").click(); //重置 input-text
				var form = liger.get("searchBar");
				 form.setData({  //重置select等特殊表单
					"groupCompanyId":"",
					"bankNature":"",
					"isOnlineAccount":"",
					"isNetBank":"",
					"accountStatus":"",
					"buOrgcd":"",
					"isStopUse":"",
				}); 
				//liger.get('cstMgrOrgCd').clear();
				//searchOrgTree.clear();
			});
		}

		//查询按钮事件
		function searchBtnEvent() {
			$("#searchBtn").click(function(event) {
				var form = new liger.get("searchBar");
				var data = form.getData();
				//alert(JSON.stringify(data));
				for (name in data) {
					grid.setParm(name, data[name]);
				}
				grid.reload();
			});
		}
		
		function toFlowList(){
			
			var selectedRows = grid.getSelectedRows();
			if(selectedRows.length == 0){
				$.ligerDialog.SQalert({content: "请选择记录" , SQ_type: "warning" });
				return;
			}
			if(selectedRows.length >= 2){
				$.ligerDialog.SQalert({content: "只能选择一条记录" , SQ_type: "warning" });
				return;
			}
			
			var title = "流程历史";
			var timestamp = new Date().getTime();
			var param = '<%=path%>/account/fncGroupCompanyAccount/toFlowList.do?id=' + selectedRows[0].id;
			Add_navTab('fncGroupCompanyAccountFlow'+timestamp,title,param, function () {
				grid.reload();
			});
			
		}
	</script>
</body>
</html>